package at.ac.tuwien.ifs.calendit.basis.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;

import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.object.MappingSqlQuery;
import org.springframework.jdbc.object.SqlUpdate;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

import at.ac.tuwien.ifs.calendit.basis.helper.Constants;
import at.ac.tuwien.ifs.calendit.dao.ITODO;
import at.ac.tuwien.ifs.calendit.domain.TODO;
import at.ac.tuwien.ifs.calendit.domain.Termin;

/**
 * Implementation of the todo Data Access Object for JDBC. This class makes
 * heavy use of the Spring Framework's facilities and provides access to the
 * data stored in the database aswell as defines how this data is mapped from
 * the application objects to the database tables.<br>
 * Also see the Bean-Config file 
 * ({@value at.ac.tuwien.ifs.bpse.basis.helper.Constants#SPRINGBEANS})
 * for configuration.
 * 
 * @author The SE-Team
 * @version 1.0
 * @see TODODAO
 */
public class JDBCTODODAO implements ITODO{
	
	/**
	 * Retrieves the logger for this class.
	 */
	private static Log log = LogFactory.getLog(JDBCTODODAO.class);

	/**
	 * SQL Datasource. In order to work with data from a database, we need to
	 * obtain a connection to the database. A Datasource is part of the JDBC
	 * specification and can be seen as a generalized connection factory.
	 */
	private DataSource dataSource = null;

	/**
	 * Transaction Manager. For encapsulating insert and updates in transaction.
	 */
	private PlatformTransactionManager transactionManager = null;
	
	/**
	 * SQL Query Strings.
	 */
	private String sql_getAllTODO = "";
	private String sql_getAllTODO2 = "";
	private String sql_getTODO = "";
	private String sql_insertTODO= "";
	private String sql_getInsertAufgabeId = ""; 
	private String sql_updateTODO = "";
	private String sql_deleteTODO = "";
	private String sql_deleteTODO2 = "";
	private String sql_deleteTODO2Arguments = "";
	private String sql_getHeute = "";
	private String sql_deleteAllTODO="";
	private String sql_get7Tage="";
	private String sql_setDone="";
	private String sql_getAbgeschlossen;
	private String sql_getOffene;
	private String sql_getHeuteAbgeschlossen;
	private String sql_getHeuteOffene;
	
	/**
	 * Query Objects.
	 */
	private Query_GetTODO query_getTODO;
	private Query_GetAllTODO query_getAllTODO;
	private Query_GetAllTODO2 query_getAllTODO2;
	private Query_InsertTODO query_insertTODO;
	private Query_UpdateTODO query_updateTODO;
	private Query_DeleteTODO query_deleteTODO;
	private Query_DeleteTODO2 query_deleteTODO2;
	private Query_DeleteTODO2Arguments query_deleteTODO2Arguments;
	private Query_DeleteAllTODO query_deleteAllTODO;
	private Query_GetTODOAufgabeId query_getTODOAufgabeId;
	private Query_GetAllTODOOrderAufgabeId query_getAllTODOOrderAufgabeId;
	private Query_GetAllTODOOrderDeadline query_getAllTODOOrderDeadline;
	private Query_GetHeute query_getHeute;
	private Query_Get7Tage query_get7Tage;
	private Query_SetDone query_setDone;
	private Query_GetAbgeschlossen query_getAbgeschlossen;
	private Query_GetOffene query_getOffene;
	private Query_GetHeuteAbgeschlossen query_getHeuteAbgeschlossen;
	private Query_GetHeuteOffene query_getHeuteOffene;


	
	/** ******************************************************************* */
	/** ******************************************************************* */
	/* INNER CLASSES TO DEFINE SQL STATEMENTS AND MAPPINGS */
	/** ******************************************************************* */
	/** ******************************************************************* */

	/**
	 * Defines the base class used for all other queries. This is a private
	 * inner class, as this is used only in this data access object
	 */
	private class BaseTODOQuery extends MappingSqlQuery {
		/**
		 * The Base query is extended by all other queries
		 * 
		 * @param ds SQL Datasource
		 * @see #dataSource
		 * @param sql  The SQL search String
		 */
		public BaseTODOQuery(DataSource ds, String sql) {
			super(ds, sql);
		}
		
		
		protected TODO mapRow(ResultSet rs, int rowNumber) 
				throws SQLException {
			TODO todo=new TODO();
			todo.setAufgabeId(rs.getInt("aufgabeId"));
			todo.setMId(rs.getInt("MID"));
			todo.setMeetingId(rs.getInt("meetingId"));
			todo.setBezeichnung(rs.getString("bezeichnung"));
			todo.setDeadlineDatum(rs.getDate("deadlineDatum"));
			todo.setDeadlineTime(rs.getTime("deadlineTime"));
			todo.setErledigt(rs.getBoolean("erledigt"));
			
			return todo;
			
		}

	}
	/**
	 * Retrieves all todo in the DB ordered by their aufgabeId. This
	 * is a private inner class, as this is used only in this data access
	 * object.
	 */
	private class Query_GetAllTODOOrderAufgabeId extends BaseTODOQuery {
		/**
		 * Fetches all todo from table
		 * 
		 * @param ds SQL Datasource
		 *            
		 * @see #dataSource
		 */
		public Query_GetAllTODOOrderAufgabeId(DataSource ds) {
			super(ds, sql_getAllTODO + " order by aufgabeId");
			super.declareParameter(new SqlParameter("MID", Types.INTEGER));
			compile();
		}
	}
	/**
	 * Retrieves all todo in the DB ordered by bezeichnung. This is a
	 * private inner class, as this is used only in this data access object.
	 */
	private class Query_GetAllTODOOrderDeadline extends BaseTODOQuery {
		/**
		 * Fetches all todo from table.
		 * 
		 * @param ds  SQL Datasource
		 * @see #dataSource
		 */
		public Query_GetAllTODOOrderDeadline(DataSource ds) {
			super(ds, sql_getAllTODO + " order by deadlineDatum");
			super.declareParameter(new SqlParameter("mId", Types.INTEGER));
			compile();
		}
	}
	/**
	 * Retrieves one todo from the DB. This is a private inner class, as this
	 * is used only in this data access object
	 */
	private class Query_GetTODO extends BaseTODOQuery {
		/**
		 * Fetches only ONE todo from database.
		 * 
		 * @param ds  SQL Datasource
		 * @see #dataSource
		 */
		public Query_GetTODO(DataSource ds) {
			super(ds, sql_getTODO);
			super.declareParameter(new SqlParameter("aufgabeId", Types.INTEGER));
			compile();
		}
	}
	/**
	 * Retrieves all todo from the DB. This is a private inner class, as this
	 * is used only in this data access object
	 */
	private class Query_GetAllTODO extends MappingSqlQuery {
		/**
		 * Fetches all todo from database.
		 * 
		 * @param ds  SQL Datasource
		 * @see #dataSource
		 */
		public Query_GetAllTODO(DataSource ds) {
			super(ds, sql_getAllTODO);
			super.declareParameter(new SqlParameter("mId", Types.INTEGER));
			compile();
		}

		
		protected Object mapRow(ResultSet rs, int rowNumber) throws SQLException {
			TODO todo=new TODO();
			todo.setAufgabeId(rs.getInt("aufgabeId"));
			todo.setMId(rs.getInt("MID"));
			todo.setMeetingId(rs.getInt("meetingId"));
			todo.setBezeichnung(rs.getString("bezeichnung"));
			todo.setDeadlineDatum(rs.getDate("deadlineDatum"));
			todo.setDeadlineTime(rs.getTime("deadlineTime"));
			todo.setErledigt(rs.getBoolean("erledigt"));
			
			return todo;
		}
	}
	
	private class Query_GetAllTODO2 extends MappingSqlQuery {
		/**
		 * Fetches all todo from database.
		 * 
		 * @param ds  SQL Datasource
		 * @see #dataSource
		 */
		public Query_GetAllTODO2(DataSource ds) {
			super(ds, sql_getAllTODO2);
//			super.declareParameter(new SqlParameter("mId", Types.INTEGER));
			compile();
		}

		
		protected Object mapRow(ResultSet rs, int rowNumber) throws SQLException {
			TODO todo=new TODO();
			todo.setAufgabeId(rs.getInt("aufgabeId"));
			todo.setMId(rs.getInt("MID"));
			todo.setMeetingId(rs.getInt("meetingId"));
			todo.setBezeichnung(rs.getString("bezeichnung"));
			todo.setDeadlineDatum(rs.getDate("deadlineDatum"));
			todo.setDeadlineTime(rs.getTime("deadlineTime"));
			todo.setErledigt(rs.getBoolean("erledigt"));
			
			return todo;
		}
	}
	/**
	 * Adds one todo to database. This is a private inner class, as this is
	 * used only in this data access object.
     * SqlUpdate is a helper class provided by the Spring-Framework
	 */
	private class Query_InsertTODO extends SqlUpdate {
		/**
		 * Retrieves the ID of the todo added to database.
		 * 
		 * @param ds  SQL Datasource
		 * @see #dataSource
		 */
		public Query_InsertTODO(DataSource ds) {
			setDataSource(ds);
			setSql(sql_insertTODO);
			declareParameter(new SqlParameter("aufgabeId", Types.INTEGER));
 			declareParameter(new SqlParameter("mId", Types.INTEGER));
 			declareParameter(new SqlParameter("meetingId", Types.INTEGER));
 			declareParameter(new SqlParameter("bezeichnung", Types.VARCHAR));
 			declareParameter(new SqlParameter("deadlineDatum", Types.DATE));
 			declareParameter(new SqlParameter("deadlineTime", Types.TIME));
 			declareParameter(new SqlParameter("erledigt", Types.BOOLEAN));
		}
	}
		
	/**
	 * Updates one todo in the database. This is a private inner class, as
	 * this is used only in this data access object.
     * SqlUpdate is a helper class provided by the Spring-Framework
	 */
	private class Query_UpdateTODO extends SqlUpdate {
		/**
		 * Create and initialises the SQL-Query for updating a todo.
		 * 
		 * @param ds  SQL Datasource
		 * @see #dataSource
		 */
		public Query_UpdateTODO(DataSource ds) {
			setDataSource(ds);
			setSql(sql_updateTODO);
 			declareParameter(new SqlParameter("mId", Types.INTEGER));
 			declareParameter(new SqlParameter("meetingId", Types.INTEGER));
 			declareParameter(new SqlParameter("bezeichnung", Types.VARCHAR));
 			declareParameter(new SqlParameter("deadlineDatum", Types.DATE));
 			declareParameter(new SqlParameter("deadlineTime", Types.TIME)); 			
 			declareParameter(new SqlParameter("erledigt", Types.BOOLEAN));
			declareParameter(new SqlParameter("aufgabeId", Types.INTEGER));

		}
	}
	/**
	 * Updates one todo in the database. This is a private inner class, as
	 * this is used only in this data access object.
     * SqlUpdate is a helper class provided by the Spring-Framework
	 */
	private class Query_SetDone extends SqlUpdate {
		/**
		 * Create and initialises the SQL-Query for done a todo.
		 * 
		 * @param ds  SQL Datasource
		 * @see #dataSource
		 */
		public Query_SetDone(DataSource ds) {
			setDataSource(ds);
			setSql(sql_setDone);
			declareParameter(new SqlParameter("aufgabeId", Types.INTEGER));
		}
	}
	
	/**
	 * Deletes one todo from the database. This is a private inner class, as
	 * this is used only in this data access object.
	 */
	public class Query_DeleteTODO extends SqlUpdate {
		/**
		 * Creates and initializes the SQL-Query for deleting a todo.
		 * 
		 * @param ds  SQL Datasource
		 * @see #dataSource
		 */
		public Query_DeleteTODO(DataSource ds) {
			setDataSource(ds);
			setSql(sql_deleteTODO);
			declareParameter(new SqlParameter("aufgabeId", Types.INTEGER));
		}
	}
	
	/**
	 * Deletes todos with the given meetingID from the database. This is a private inner class, as
	 * this is used only in this data access object.
	 */
	public class Query_DeleteTODO2 extends SqlUpdate {
		/**
		 * Creates and initializes the SQL-Query for deleting a todo.
		 * 
		 * @param ds  SQL Datasource
		 * @see #dataSource
		 */
		public Query_DeleteTODO2(DataSource ds) {
			setDataSource(ds);
			setSql(sql_deleteTODO2);
			declareParameter(new SqlParameter("meetingId", Types.INTEGER));
		}
	}
	
	/**
	 * Deletes one todo from the database. This is a private inner class, as
	 * this is used only in this data access object.
	 */
	public class Query_DeleteTODO2Arguments extends SqlUpdate {
		/**
		 * Creates and initializes the SQL-Query for deleting a todo.
		 * 
		 * @param ds  SQL Datasource
		 * @see #dataSource8	 */
		public Query_DeleteTODO2Arguments(DataSource ds) {
			setDataSource(ds);
			setSql(sql_deleteTODO2Arguments);
			declareParameter(new SqlParameter("mID", Types.INTEGER));
			declareParameter(new SqlParameter("meetingId", Types.INTEGER));
		}
	}
	
	/**
	 * Deletes all todo from the database. This is a private inner class, as
	 * this is used only in this data access object.
	 */
	private class Query_DeleteAllTODO extends SqlUpdate {
	 		/***
	 		 * Creates and initializes the SQL-Query for deleting a Termin.
	 		 * 
     		 * @param ds  SQL Datasource
	 		 * @see #dataSource
	 		 */
		public Query_DeleteAllTODO(DataSource ds) {
			setDataSource(ds);
			setSql(sql_deleteAllTODO);
			declareParameter(new SqlParameter("aufgabeId", Types.INTEGER));
			

		}
	 	}
	
		/**
		 * Retrieves the aufgabeId of the todo added to database. This is a private
		 * inner class, as this is used only in this data access object.
		 */
		private class Query_GetTODOAufgabeId extends MappingSqlQuery {
			/**
			 * Retrieves the aufgabeId of the todo added to database.
			 * 
			 * @param ds
			 * SQL Datasource
			 * @see #dataSource
			 */
			public Query_GetTODOAufgabeId(DataSource ds) {
				super(ds, sql_getInsertAufgabeId);
				compile();
			}

			protected Object mapRow(ResultSet rs, int rowNumber)
					throws SQLException {
				
				// "@p0" is the row name hsqldb creates for the one value returning
				// the aufgabeId
				Integer aufgabeId = new Integer(rs.getInt("@p0"));
				return aufgabeId;
			}
		}
	   
		private class Query_GetHeute extends MappingSqlQuery{
			/**
			 * Retrieves the todo from today added to database.
			 * 
			 * @param ds
			 * SQL Datasource
			 * @see #dataSource
			 */
			public Query_GetHeute(DataSource ds) {
//				setDataSource(ds);
//				setSql(sql_getHeute);
				super(ds, sql_getHeute);
				declareParameter(new SqlParameter("mid", Types.INTEGER));

				compile();
			}

			protected Object mapRow(ResultSet rs, int rowNumber)
					throws SQLException {
				
				TODO todo = new TODO();
				todo.setAufgabeId(rs.getInt("aufgabeId"));
				todo.setMId(rs.getInt("MID"));
				todo.setMeetingId(rs.getInt("meetingId"));
				todo.setBezeichnung(rs.getString("bezeichnung"));
				todo.setDeadlineDatum(rs.getDate("deadlineDatum"));
				todo.setDeadlineTime(rs.getTime("deadlineTime"));
				todo.setErledigt(rs.getBoolean("erledigt"));
				return todo;
			}
		}
		private class Query_GetAbgeschlossen extends MappingSqlQuery{

			/**
			 * Retrieves the todo who are finished added to database.
			 * 
			 * @param ds
			 * SQL Datasource
			 * @see #dataSource
			 */
			public Query_GetAbgeschlossen(DataSource ds) {
				super(ds, sql_getAbgeschlossen);
			super.declareParameter(new SqlParameter("mId", Types.DATE));
				compile();
			}

			protected Object mapRow(ResultSet rs, int rowNumber)
					throws SQLException {
				
				TODO todo = new TODO();
				todo.setAufgabeId(rs.getInt("aufgabeId"));
				todo.setMId(rs.getInt("MID"));
				todo.setMeetingId(rs.getInt("meetingId"));
				todo.setBezeichnung(rs.getString("bezeichnung"));
				todo.setDeadlineDatum(rs.getDate("deadlineDatum"));
				todo.setDeadlineTime(rs.getTime("deadlineTime"));
				todo.setErledigt(rs.getBoolean("erledigt"));
				return todo;
			}

		}
		
		private class Query_GetOffene extends MappingSqlQuery{

			/**
			 * Retrieves the todo who are finished added to database.
			 * 
			 * @param ds
			 * SQL Datasource
			 * @see #dataSource
			 */
			public Query_GetOffene(DataSource ds) {
				super(ds, sql_getOffene);
			//	super.declareParameter(new SqlParameter("erledigt", Types.BOOLEAN));
				super.declareParameter(new SqlParameter("mid",Types.INTEGER));
				//compile();
			}

			protected Object mapRow(ResultSet rs, int rowNumber)
					throws SQLException {
				
				TODO todo = new TODO();
				todo.setAufgabeId(rs.getInt("aufgabeId"));
				todo.setMId(rs.getInt("MID"));
				todo.setMeetingId(rs.getInt("meetingId"));
				todo.setBezeichnung(rs.getString("bezeichnung"));
				todo.setDeadlineDatum(rs.getDate("deadlineDatum"));
				todo.setDeadlineTime(rs.getTime("deadlineTime"));
				todo.setErledigt(rs.getBoolean("erledigt"));
				return todo;
			}

		}
		
		private class Query_Get7Tage extends MappingSqlQuery{
			/**
			 * Retrieves the todo from the next seven days added to database.
			 * 
			 * @param ds
			 * SQL Datasource
			 * @see #dataSource
			 */
			public Query_Get7Tage(DataSource ds) {
				super(ds, sql_get7Tage);
				//super.declareParameter(new SqlParameter("deadlineDatum", Types.DATE));
				declareParameter(new SqlParameter("mid", Types.INTEGER));
				compile();
			}

			protected Object mapRow(ResultSet rs, int rowNumber)
					throws SQLException {
				
				TODO todo = new TODO();
				todo.setAufgabeId(rs.getInt("aufgabeId"));
				todo.setMId(rs.getInt("MID"));
				todo.setMeetingId(rs.getInt("meetingId"));
				todo.setBezeichnung(rs.getString("bezeichnung"));
				todo.setDeadlineDatum(rs.getDate("deadlineDatum"));
				todo.setDeadlineTime(rs.getTime("deadlineTime"));
				todo.setErledigt(rs.getBoolean("erledigt"));
				return todo;
			}

		}
		private class Query_GetHeuteAbgeschlossen extends MappingSqlQuery{
			/**
			 * Retrieves the todo from today and are finished added to database.
			 * 
			 * @param ds
			 * SQL Datasource
			 * @see #dataSource
			 */
			public Query_GetHeuteAbgeschlossen(DataSource ds) {
//				setDataSource(ds);
//				setSql(sql_getHeute);
				super(ds, sql_getHeuteAbgeschlossen);
				declareParameter(new SqlParameter("mid", Types.INTEGER));

				compile();
			}

			protected Object mapRow(ResultSet rs, int rowNumber)
					throws SQLException {
				
				TODO todo = new TODO();
				todo.setAufgabeId(rs.getInt("aufgabeId"));
				todo.setMId(rs.getInt("MID"));
				todo.setMeetingId(rs.getInt("meetingId"));
				todo.setBezeichnung(rs.getString("bezeichnung"));
				todo.setDeadlineDatum(rs.getDate("deadlineDatum"));
				todo.setDeadlineTime(rs.getTime("deadlineTime"));
				todo.setErledigt(rs.getBoolean("erledigt"));
				return todo;
			}
		}
		private class Query_GetHeuteOffene extends MappingSqlQuery{
			/**
			 * Retrieves the todo from today and are not finished added to database.
			 * 
			 * @param ds
			 * SQL Datasource
			 * @see #dataSource
			 */
			public Query_GetHeuteOffene(DataSource ds) {
//				setDataSource(ds);
//				setSql(sql_getHeute);
				super(ds, sql_getHeuteOffene);
				declareParameter(new SqlParameter("mid", Types.INTEGER));

				compile();
			}

			protected Object mapRow(ResultSet rs, int rowNumber)
					throws SQLException {
				
				TODO todo = new TODO();
				todo.setAufgabeId(rs.getInt("aufgabeId"));
				todo.setMId(rs.getInt("MID"));
				todo.setMeetingId(rs.getInt("meetingId"));
				todo.setBezeichnung(rs.getString("bezeichnung"));
				todo.setDeadlineDatum(rs.getDate("deadlineDatum"));
				todo.setDeadlineTime(rs.getTime("deadlineTime"));
				todo.setErledigt(rs.getBoolean("erledigt"));
				return todo;
			}
		}

		/** ******************************************************************* */
		/** ******************************************************************* */
		/* C O N S T R U C T O R */
		/** ******************************************************************* */
		/** ******************************************************************* */

		public JDBCTODODAO() {
			super();
		}
		/**
		 * The Initialise Method must be called after all bean values are set,
		 * particularly the datasource and the transaction manager. This is actually
		 * performed by the Spring Framework, which sets first of all, all Java Bean
		 * Properties and eventually calls this init method (see bean definition in
		 * beans.xml configuration file)
		 */
		public void init() {
			log.info("Initialise TODODAO");
			query_getTODO = new Query_GetTODO(dataSource);
			query_getAllTODO = new  Query_GetAllTODO(dataSource);
			query_getAllTODO2 = new  Query_GetAllTODO2(dataSource);
			query_insertTODO = new Query_InsertTODO(dataSource);
			query_getTODOAufgabeId = new Query_GetTODOAufgabeId(dataSource);
			query_updateTODO = new Query_UpdateTODO(dataSource);
			query_deleteTODO = new Query_DeleteTODO(dataSource);
			query_deleteTODO2 = new Query_DeleteTODO2(dataSource);
			query_deleteTODO2Arguments = new Query_DeleteTODO2Arguments(dataSource);
			query_getAllTODOOrderAufgabeId = new Query_GetAllTODOOrderAufgabeId(dataSource);
			query_getAllTODOOrderDeadline = new Query_GetAllTODOOrderDeadline(
					dataSource);
			query_deleteAllTODO= new Query_DeleteAllTODO(dataSource) ;
			query_getHeute = new Query_GetHeute(dataSource) ;
			query_get7Tage = new Query_Get7Tage(dataSource);
			query_setDone = new Query_SetDone (dataSource) ;
			//query_getAbgeschlossen = new Query_GetAbgeschlossen (dataSource);
//			query_getOffene = new Query_GetOffene (dataSource) ;
			query_getHeuteAbgeschlossen=new Query_GetHeuteAbgeschlossen(dataSource);
			query_getHeuteOffene=new Query_GetHeuteOffene(dataSource);
			query_getOffene= new Query_GetOffene(dataSource);
			query_getAbgeschlossen= new Query_GetAbgeschlossen(dataSource);
		}
		
		/**
		 * The Destroy Method is called by the Spring Framework to end the lifecycle
		 * of this bean, but <b>only</b> when the bean is created as singleton.
		 * Check the bean definition in beans.xml configuration file for details.
		 */
		public void destroy() {
			log.info("Destroy TODODAO");
		}
		
		/** ******************************************************************* */
		/** ******************************************************************* */
		/*
		 * BEAN SETTERS FOR DEPENDENCY INJECTION
		 * 
		 * Dependency Injection is a design pattern in which the responsibility for
		 * object creation and object linking is removed from the objects themselves
		 * and transferred to a factory object. It is a way to achieve loose
		 * coupling between objects and results in highly testable objects
		 * (controlled unit tests).
		 * 
		 * Factory Object: (Design Pattern) is an object for creating other objects.
		 * Typically a factory has a method for every kind of object it is capable
		 * of creating. these methods optionally accept parameters defining how the
		 * object is created and then return the created object.
		 */
		/** ******************************************************************* */
		/** ******************************************************************* */

		/**
		 * Sets the SQL String to get all todo.
		 * 
		 * @param sql_getAllTODO
		 *            SQL Statement as String
		 */
		public void setSql_getAllTODO(String sql_getAllTODO) {
			this.sql_getAllTODO = sql_getAllTODO;
		}
				/**
		 * Sets the SQL String to get one todo with one SQL parameter.
		 * 
		 * @param sql_getTODO
		 *            SQL Statement as String
		 */
		public void setSql_getTODO(String sql_getTODO) {
			this.sql_getTODO = sql_getTODO;
		}
		/**
		 * Sets the SQL String to insert one todo into the database.
		 * 
		 * @param sql_insertTODO
		 *            SQL Statement as String
		 */
		public void setSql_insertTODO(String sql_insertTODO) {
			this.sql_insertTODO = sql_insertTODO;
		}

		/**
		 * Sets the SQL String to retrieve the aufgabeId of the last executed SQL
		 * Statement.
		 * 
		 * @param sql_getInsertAufgabeId
		 *            SQL Statement as String
		 */
		public void setSql_getInsertAufgabeId(String sql_getInsertAufgabeId) {
			this.sql_getInsertAufgabeId = sql_getInsertAufgabeId;
		}
		
		/**
		 * Sets the SQL String to update a todo.
		 * 
		 * @param sql_updateTODO
		 *            SQL Statement as String
		 */
		public void setSql_updateTODO(String sql_updateTODO) {
			this.sql_updateTODO = sql_updateTODO;
		}
		
		/**
		 * Sets the SQL String to delete a todo.
		 * 
		 * @param sql_deleteTODO
		 *            SQL Statement as String
		 */
		public void setSql_deleteTODO(String sql_deleteTODO) {
			this.sql_deleteTODO = sql_deleteTODO;
		}
		
		/**
		 * Sets the SQL String to delete all todos.
		 * 
		 * @param sql_deleteAllTODO
		 *            SQL Statement as String
		 */
		public void setSql_deleteAllTODO(String sql_deleteAllTODO) {
			this.sql_deleteAllTODO = sql_deleteAllTODO;
		}
		
		/**
		 * Sets the SQL String to give the todos from today.
		 * 
		 * @param sql_getHeuteTODO
		 *            SQL Statement as String
		 */
		public void setSql_getHeute(String sql_getHeute) {    
			this.sql_getHeute = sql_getHeute;
		}
		
		/**
		 * Sets the SQL String to give the todos from the next seven days.
		 * 
		 * @param sql_get7Tage
		 *            SQL Statement as String
		 */
		public void setSql_get7Tage(String sql_get7Tage) {
			this.sql_get7Tage = sql_get7Tage;
		}
		/**
		 * Sets the SQL String to give the todos that are marked done.
		 * 
		 * @param sql_setDone
		 *            SQL Statement as String
		 */
		public void setSql_setDone(String sql_setDone) {
			this.sql_setDone = sql_setDone;
		}
		/**
		 * Sets the SQL String to give the todos that are finished.
		 * 
		 * @param sql_getAbgeschlossen
		 *            SQL Statement as String
		 */
		public void setSql_getAbgeschlossen(String sql_getAbgeschlossen) {
			this.sql_getAbgeschlossen = sql_getAbgeschlossen;
		}
		
		/**
		 * Sets the SQL String to give the todos that are not finished.
		 * 
		 * @param sql_getOffene
		 *            SQL Statement as String
		 */
		public void setSql_getOffene(String sql_getOffene) {
			this.sql_getOffene = sql_getOffene;
		}
		
		
		
	
	/**
		 * @return the log
		 */
		public static Log getLog() {
			return log;
		}
		/**
		 * @param log the log to set
		 */
		public static void setLog(Log log) {
			JDBCTODODAO.log = log;
		}
		/**
		 * @return the sql_getAllTODO2
		 */
		public String getSql_getAllTODO2() {
			return sql_getAllTODO2;
		}
		/**
		 * @param sqlGetAllTODO2 the sql_getAllTODO2 to set
		 */
		public void setSql_getAllTODO2(String sqlGetAllTODO2) {
			sql_getAllTODO2 = sqlGetAllTODO2;
		}
		/**
		 * @return the query_getTODO
		 */
		public Query_GetTODO getQuery_getTODO() {
			return query_getTODO;
		}
		/**
		 * @param queryGetTODO the query_getTODO to set
		 */
		public void setQuery_getTODO(Query_GetTODO queryGetTODO) {
			query_getTODO = queryGetTODO;
		}
		/**
		 * @return the query_getAllTODO
		 */
		public Query_GetAllTODO getQuery_getAllTODO() {
			return query_getAllTODO;
		}
		/**
		 * @param queryGetAllTODO the query_getAllTODO to set
		 */
		public void setQuery_getAllTODO(Query_GetAllTODO queryGetAllTODO) {
			query_getAllTODO = queryGetAllTODO;
		}
		/**
		 * @return the query_getAllTODO2
		 */
		public Query_GetAllTODO2 getQuery_getAllTODO2() {
			return query_getAllTODO2;
		}
		/**
		 * @param queryGetAllTODO2 the query_getAllTODO2 to set
		 */
		public void setQuery_getAllTODO2(Query_GetAllTODO2 queryGetAllTODO2) {
			query_getAllTODO2 = queryGetAllTODO2;
		}
		/**
		 * @return the query_insertTODO
		 */
		public Query_InsertTODO getQuery_insertTODO() {
			return query_insertTODO;
		}
		/**
		 * @param queryInsertTODO the query_insertTODO to set
		 */
		public void setQuery_insertTODO(Query_InsertTODO queryInsertTODO) {
			query_insertTODO = queryInsertTODO;
		}
		/**
		 * @return the query_updateTODO
		 */
		public Query_UpdateTODO getQuery_updateTODO() {
			return query_updateTODO;
		}
		/**
		 * @param queryUpdateTODO the query_updateTODO to set
		 */
		public void setQuery_updateTODO(Query_UpdateTODO queryUpdateTODO) {
			query_updateTODO = queryUpdateTODO;
		}
		/**
		 * @return the query_deleteTODO
		 */
		public Query_DeleteTODO getQuery_deleteTODO() {
			return query_deleteTODO;
		}
		/**
		 * @param queryDeleteTODO the query_deleteTODO to set
		 */
		public void setQuery_deleteTODO(Query_DeleteTODO queryDeleteTODO) {
			query_deleteTODO = queryDeleteTODO;
		}
		/**
		 * @return the query_deleteAllTODO
		 */
		public Query_DeleteAllTODO getQuery_deleteAllTODO() {
			return query_deleteAllTODO;
		}
		/**
		 * @param queryDeleteAllTODO the query_deleteAllTODO to set
		 */
		public void setQuery_deleteAllTODO(Query_DeleteAllTODO queryDeleteAllTODO) {
			query_deleteAllTODO = queryDeleteAllTODO;
		}
		/**
		 * @return the query_getTODOAufgabeId
		 */
		public Query_GetTODOAufgabeId getQuery_getTODOAufgabeId() {
			return query_getTODOAufgabeId;
		}
		/**
		 * @param queryGetTODOAufgabeId the query_getTODOAufgabeId to set
		 */
		public void setQuery_getTODOAufgabeId(
				Query_GetTODOAufgabeId queryGetTODOAufgabeId) {
			query_getTODOAufgabeId = queryGetTODOAufgabeId;
		}
		/**
		 * @return the query_getAllTODOOrderAufgabeId
		 */
		public Query_GetAllTODOOrderAufgabeId getQuery_getAllTODOOrderAufgabeId() {
			return query_getAllTODOOrderAufgabeId;
		}
		/**
		 * @param queryGetAllTODOOrderAufgabeId the query_getAllTODOOrderAufgabeId to set
		 */
		public void setQuery_getAllTODOOrderAufgabeId(
				Query_GetAllTODOOrderAufgabeId queryGetAllTODOOrderAufgabeId) {
			query_getAllTODOOrderAufgabeId = queryGetAllTODOOrderAufgabeId;
		}
		/**
		 * @return the query_getAllTODOOrderDeadline
		 */
		public Query_GetAllTODOOrderDeadline getQuery_getAllTODOOrderDeadline() {
			return query_getAllTODOOrderDeadline;
		}
		/**
		 * @param queryGetAllTODOOrderDeadline the query_getAllTODOOrderDeadline to set
		 */
		public void setQuery_getAllTODOOrderDeadline(
				Query_GetAllTODOOrderDeadline queryGetAllTODOOrderDeadline) {
			query_getAllTODOOrderDeadline = queryGetAllTODOOrderDeadline;
		}
		/**
		 * @return the query_getHeute
		 */
		public Query_GetHeute getQuery_getHeute() {
			return query_getHeute;
		}
		/**
		 * @param queryGetHeute the query_getHeute to set
		 */
		public void setQuery_getHeute(Query_GetHeute queryGetHeute) {
			query_getHeute = queryGetHeute;
		}
		/**
		 * @return the query_get7Tage
		 */
		public Query_Get7Tage getQuery_get7Tage() {
			return query_get7Tage;
		}
		/**
		 * @param queryGet7Tage the query_get7Tage to set
		 */
		public void setQuery_get7Tage(Query_Get7Tage queryGet7Tage) {
			query_get7Tage = queryGet7Tage;
		}
		/**
		 * @return the query_setDone
		 */
		public Query_SetDone getQuery_setDone() {
			return query_setDone;
		}
		/**
		 * @param querySetDone the query_setDone to set
		 */
		public void setQuery_setDone(Query_SetDone querySetDone) {
			query_setDone = querySetDone;
		}
		/**
		 * @return the query_getAbgeschlossen
		 */
		public Query_GetAbgeschlossen getQuery_getAbgeschlossen() {
			return query_getAbgeschlossen;
		}
		/**
		 * @param queryGetAbgeschlossen the query_getAbgeschlossen to set
		 */
		public void setQuery_getAbgeschlossen(
				Query_GetAbgeschlossen queryGetAbgeschlossen) {
			query_getAbgeschlossen = queryGetAbgeschlossen;
		}
		/**
		 * @return the query_getOffene
		 */
		public Query_GetOffene getQuery_getOffene() {
			return query_getOffene;
		}
		/**
		 * @param queryGetOffene the query_getOffene to set
		 */
		public void setQuery_getOffene(Query_GetOffene queryGetOffene) {
			query_getOffene = queryGetOffene;
		}
		/**
		 * @return the dataSource
		 */
		public DataSource getDataSource() {
			return dataSource;
		}
		/**
		 * @return the transactionManager
		 */
		public PlatformTransactionManager getTransactionManager() {
			return transactionManager;
		}
		/**
		 * @return the sql_getAllTODO
		 */
		public String getSql_getAllTODO() {
			return sql_getAllTODO;
		}
		/**
		 * @return the sql_getTODO
		 */
		public String getSql_getTODO() {
			return sql_getTODO;
		}
		/**
		 * @return the sql_insertTODO
		 */
		public String getSql_insertTODO() {
			return sql_insertTODO;
		}
		/**
		 * @return the sql_getInsertAufgabeId
		 */
		public String getSql_getInsertAufgabeId() {
			return sql_getInsertAufgabeId;
		}
		/**
		 * @return the sql_updateTODO
		 */
		public String getSql_updateTODO() {
			return sql_updateTODO;
		}
		/**
		 * @return the sql_deleteTODO
		 */
		public String getSql_deleteTODO() {
			return sql_deleteTODO;
		}
		/**
		 * @return the sql_getHeute
		 */
		public String getSql_getHeute() {
			return sql_getHeute;
		}
		/**
		 * @return the sql_deleteAllTODO
		 */
		public String getSql_deleteAllTODO() {
			return sql_deleteAllTODO;
		}
		/**
		 * @return the sql_get7Tage
		 */
		public String getSql_get7Tage() {
			return sql_get7Tage;
		}
		/**
		 * @return the sql_setDone
		 */
		public String getSql_setDone() {
			return sql_setDone;
		}
		/**
		 * @return the sql_getAbgeschlossen
		 */
		public String getSql_getAbgeschlossen() {
			return sql_getAbgeschlossen;
		}
		/**
		 * @return the sql_getOffene
		 */
		public String getSql_getOffene() {
			return sql_getOffene;
		}
		public void setSql_getHeuteOffene(String sql_getHeuteOffene) {
			this.sql_getHeuteOffene = sql_getHeuteOffene;
		}
		public void setSql_getHeuteAbgeschlossen(String sql_getHeuteAbgeschlossen) {
			this.sql_getHeuteAbgeschlossen = sql_getHeuteAbgeschlossen;
		}
		
		
		
	/**
		 * @return the sql_deleteTODO2
		 */
		public String getSql_deleteTODO2() {
			return sql_deleteTODO2;
		}
		/**
		 * @param sqlDeleteTODO2 the sql_deleteTODO2 to set
		 */
		public void setSql_deleteTODO2(String sqlDeleteTODO2) {
			sql_deleteTODO2 = sqlDeleteTODO2;
		}
		/**
		 * @return the query_deleteTODO2
		 */
		public Query_DeleteTODO2 getQuery_deleteTODO2() {
			return query_deleteTODO2;
		}
		/**
		 * @param queryDeleteTODO2 the query_deleteTODO2 to set
		 */
		public void setQuery_deleteTODO2(Query_DeleteTODO2 queryDeleteTODO2) {
			query_deleteTODO2 = queryDeleteTODO2;
		}
		
		
	/**
		 * @return the sql_deleteTODO2Arguments
		 */
		public String getSql_deleteTODO2Arguments() {
			return sql_deleteTODO2Arguments;
		}
		/**
		 * @param sqlDeleteTODO2Arguments the sql_deleteTODO2Arguments to set
		 */
		public void setSql_deleteTODO2Arguments(String sqlDeleteTODO2Arguments) {
			sql_deleteTODO2Arguments = sqlDeleteTODO2Arguments;
		}
		/**
		 * @return the query_deleteTODO2Arguments
		 */
		public Query_DeleteTODO2Arguments getQuery_deleteTODO2Arguments() {
			return query_deleteTODO2Arguments;
		}
		/**
		 * @param queryDeleteTODO2Arguments the query_deleteTODO2Arguments to set
		 */
		public void setQuery_deleteTODO2Arguments(
				Query_DeleteTODO2Arguments queryDeleteTODO2Arguments) {
			query_deleteTODO2Arguments = queryDeleteTODO2Arguments;
		}
		/**
		 * @return the query_getHeuteAbgeschlossen
		 */
		public Query_GetHeuteAbgeschlossen getQuery_getHeuteAbgeschlossen() {
			return query_getHeuteAbgeschlossen;
		}
		/**
		 * @param queryGetHeuteAbgeschlossen the query_getHeuteAbgeschlossen to set
		 */
		public void setQuery_getHeuteAbgeschlossen(
				Query_GetHeuteAbgeschlossen queryGetHeuteAbgeschlossen) {
			query_getHeuteAbgeschlossen = queryGetHeuteAbgeschlossen;
		}
		/**
		 * @return the query_getHeuteOffene
		 */
		public Query_GetHeuteOffene getQuery_getHeuteOffene() {
			return query_getHeuteOffene;
		}
		/**
		 * @param queryGetHeuteOffene the query_getHeuteOffene to set
		 */
		public void setQuery_getHeuteOffene(Query_GetHeuteOffene queryGetHeuteOffene) {
			query_getHeuteOffene = queryGetHeuteOffene;
		}
		/**
		 * @return the sql_getHeuteAbgeschlossen
		 */
		public String getSql_getHeuteAbgeschlossen() {
			return sql_getHeuteAbgeschlossen;
		}
		/**
		 * @return the sql_getHeuteOffene
		 */
		public String getSql_getHeuteOffene() {
			return sql_getHeuteOffene;
		}
	/**
	 * Sets the Datasource to connect to database.
	 * 
	 * @param dataSource
	 * SQL Datasource
	 * @see #dataSource
	 */
	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	/**
	 * Sets the transaction manager.
	 * 
	 * @param transactionManager 
	 * central interface in Spring's transaction infrastructure
	 * @see #transactionManager
	 */
	public void setTransactionManager(
			PlatformTransactionManager transactionManager) {
		this.transactionManager = transactionManager;
	}
	
	/** ******************************************************************* */
	/** ******************************************************************* */
	/*
	 * DAO METHODS
	 * 
	 * A Data Access Object (DAO) is a component which provides a common
	 * interface between the application and one or more data storage devices,
	 * such as a database or a file. The advantage of using data access objects
	 * is that any business object (which contains application or operation
	 * specific details) does not require direct knowledge of the final
	 * destination for the information it manipulates. As a result, _if_ it is
	 * necessary to change where or how the data is stored, these modifications
	 * can be made without needing to change the main application.
	 */
	/** ******************************************************************* */
	/** ******************************************************************* */

	

	public TODO getById(int aufgabeId) {
		log.info("Get TODO ID = " + aufgabeId);
		List todo = query_getTODO.execute(aufgabeId);
		if (todo.size() == 1) {
			TODO t = (TODO) todo.get(0);
			log.debug("Returning TODO \"" + t.getBezeichnung() + " "
					+ t.getDeadlineDatum() + t.getDeadlineTime() +"\"");
			return t;
    	} else {
			log.debug("No TODO data");
			return null;
		}
	}
	
	
	/**
	 * Inserts one todo into the database. This method uses a transaction
	 * manager for performing two queries in one transaction:
	 * <ol>
	 * <li> the insert statement is performed adding the dataset to the database
	 * (first query)</li>
	 * <li> the database then automatically generates a unique ID for this
	 * dataset, </li>
	 * <li> the second query asks the database <i>which</i> id was used for
	 * this particular dataset</li>
	 * <li> this ID then is set in the todo bean and returned by the function</li>
	 * </ol>
	 * 
	 * @param todo
	 *            todo object holding data of one todo
	 * @return unique id generated by database assigned to the newly created
	 *         todo
	 */
	public TODO add(TODO todo) {
		log.info("Add Aufgabe Id = " + todo.getAufgabeId());
		log.debug("Initialise SQL Parameters");
		final Object[] param = new Object[] {null,
				todo.getMId(),todo.getMeetingId(),todo.getBezeichnung(),
				todo.getDeadlineDatum(), todo.getDeadlineTime(), todo.isErledigt()};
		log.debug("Initialise Transaction Manager");
		TransactionTemplate tt=new TransactionTemplate(transactionManager);
		Object result = tt.execute(new TransactionCallback() {
			public Object doInTransaction(TransactionStatus status) {
				// The transaction is run from here
				log.debug("Start Transaction");
				query_insertTODO.update(param);
				
				/**
				 * activate the following error line to create an Error which
				 * terminates this method. One will see, that the complete
				 * transaction is rolled back, hence the insert statement above
				 * is not executed, alternatively the second rollback statement
				 * can be activated with the same result which in that case is a
				 * manual rollback of the transaction
				 */

				// if (true) throw new Error("Test Exception");
				// or
				// status.setRollbackOnly();
				
				/**
				 * result from query is a list, actually containing only one row
				 * and one column
				 */
				List results = query_getTODOAufgabeId.execute();
				Integer aufgabeId = (Integer) results.get(0);
				log.debug("End Transaction");
				return aufgabeId;
				/**
				 * and the transaction ends here! if no error occurs the
				 * transaction is committed by Spring otherwise it is rolled
				 * back
				 */
			}
		});
		Integer aufgabeId = (Integer) result;
		todo.setAufgabeId(aufgabeId);
		log.info("Return aufgabeId from inserted dataset = " + aufgabeId);
		return (aufgabeId!=0) ? todo : null;

	}

	/**
	* Updates one todo in the database. This is a private inner class, as
	* this is used only in this data access object.
	* SqlUpdate is a helper class provided by the Spring-Framework
	*/
	public TODO update(TODO todo) {
		return updateTODO(todo, todo.getAufgabeId());
	}
	
	private TODO updateTODO(TODO todo, long aufgabeId) {
		log.info("Update TODO, aufgabeId = " + todo.getAufgabeId() + " new aufgabeId = "
				+ aufgabeId);
		log.debug("Initialise SQL Parameters");
		final Object[] param = new Object[] { 
				todo.getMId(),todo.getMeetingId(),todo.getBezeichnung(),
				todo.getDeadlineDatum(), todo.getDeadlineTime(), todo.isErledigt(), aufgabeId };
		log.debug("Execute Update");
		if (query_updateTODO.update(param) == 1) {
			log.debug("Update Successfull");
			return todo;
		}
		log.error("Update for TODO ID = " + aufgabeId  + " failed.");
		
		return null;
	}


	public boolean delete(int aufgabeId) {
			log.info("Delete TODO aufgabeID = " + aufgabeId);
			log.debug("Initialize SQL Parameters");
			final Object[] param = new Object[] { aufgabeId };
			log.debug("Executing SQL");
			if (query_deleteTODO.update(param) == 1) {
				log.debug("Deleting successfull");
				return true;
			}
			log.error("Deleting TODO aufgabeID = " + aufgabeId + " failed");
			return false;
	}
	
	public boolean deleteByKennung(int aufgabeId) {
		log.info("Delete TODO aufgabeID = " + aufgabeId);
		log.debug("Initialize SQL Parameters");
		final Object[] param = new Object[] { aufgabeId };
		log.debug("Executing SQL");

		int a= query_deleteTODO2.update(param);
//		System.out.println("deleted rows:" + a);
		if (a==0) {
			log.error("Deleting failed");
			return false;
		}
		log.debug("Deleted rows = " + a) ;
		return true;
}

	public boolean deleteWith2Arguments(TODO t) {
		log.info("Delete TODO aufgabeID = " + t.getAufgabeId()+"meetingid= "+t.getMeetingId());
		log.debug("Initialize SQL Parameters");
		final Object[] param = new Object[] { t.getMeetingId(),t.getMId() };
		log.debug("Executing SQL");

		int a= query_deleteTODO2Arguments.update(param);
//		System.out.println("deleted rows:" + a);
		if (a==0) {
			log.error("Deleting failed");
			return false;
		}
		log.debug("Deleted rows = " + a) ;
		return true;
}
	
	public boolean done(int aufgabeId){
		log.info("Set TODO to done");
		log.debug("Initialize SQL Parameters");
		if(query_setDone.update(aufgabeId)==1){
			log.debug("Done successfull");
			return true;
		}
		log.debug("Done failleid!");
		return false;
		
	}
	
	public boolean deleteAll() {
		log.info("Delete All TODO = ");

		if (!(query_deleteAllTODO.update() == 1)) {
			log.debug("Deleting all TODO successfull");
			return true;
		}
		log.debug("Deleting All TODO failed");
		return false;	}

	public List<TODO> getAll() {
		log.info("Get all TODO");
//		final Object[] param = new Object[] {todo.getMId()};
		
		List<TODO> t =query_getAllTODO.execute(Constants.getUserId());
		
		log.debug("TODO List contains " + t.size() + " todo");
		return t;	
		
	}
	
	public List<TODO> getAll2() {
		log.info("Get all TODO");
//		final Object[] param = new Object[] {todo.getMId()};
		
		List<TODO> t =query_getAllTODO2.execute();
		
		log.debug("TODO List contains " + t.size() + " todo");
		return t;	
		
	}
	
	public List<TODO> getAbgeschlossen(){
		log.info("Get all TODO that are finished");
		//final Object[] param = new Object[]{ todo.isErledigt()};
		
		List<TODO> t = query_getAbgeschlossen.execute(Constants.getUserId());
		     
		return t;
//		if(t.size() != 0){
//			TODO t1=(TODO) t.get(0);
//			log.debug("TODO List contains " + t1.isErledigt() + "todo");
//			return t;
//		}else{
//			log.debug("No TODO data");}
//			return null;
	}
	
	public List<TODO> getOffene(){
		log.info("Get all TODO that are not finished");
		
	//	final Object[] param = new Object[]{ todo.isErledigt()};

		List<TODO> t =query_getOffene.execute(Constants.getUserId());
		     
		log.debug("TODO List contains " + t.size() + "todo");
		return t;
	}
	/**
	 * Retrieves all todo from the database. <br>
	 * <b>Warning:</b> this type of DAO method would not be used in a real-
	 * world application because there may be thousands of todo in the
	 * database and this method would retrieve them all. <br>
	 * This is usually not needed: it will generate a huge load on the database
	 * and also require enormous amounts of memory. Morover, there is hardly an
	 * application conceivable that needs more than a few dozen datasets at any
	 * one time.
	 */
	public List<TODO> getTODO(String order) {
		log.info("Get TODO order = " + order);
		List<TODO> todo = null;
		if (order.equals("aufgabeId")) {
			todo = query_getAllTODOOrderAufgabeId.execute(Constants.getUserId());
		} else if (order.equals("deadlineDatum")) {
			todo = query_getAllTODOOrderDeadline.execute(Constants.getUserId());
		}
		log.debug("TODO List contains " + todo.size() + " todo");
		return todo;
	}
	public List<TODO>getHeuteAbgeschlossen(){
		log.info("Get all TODO that are finished and from today");

		List<TODO> t=query_getHeuteAbgeschlossen.execute(Constants.getUserId());
		
		log.debug("TODO List contains " + t.size() + "todo");

		return t;
	}
	public List<TODO>getHeuteOffene(){
		log.info("Get all TODO that are not finished and from today");

		List<TODO> t=query_getHeuteOffene.execute(Constants.getUserId());
		
		log.debug("TODO List contains " + t.size() + "todo");

		return t;
	}
	
	/**
	 * Retrieves todo from the day from the database. <br>
	 * <b>Warning:</b> this type of DAO method would not be used in a real-
	 * world application because there may be thousands of todo in the
	 * database and this method would retrieve them all. <br>
	 * This is usually not needed: it will generate a huge load on the database
	 * and also require enormous amounts of memory. Morover, there is hardly an
	 * application conceivable that needs more than a few dozen datasets at any
	 * one time.
	 */
	
	
	public List<TODO> getTODOHeute() {
		log.info("Get all TODO from today" );
		
//		final Object[] param = new Object[] { };
		
		List<TODO> t = query_getHeute.execute(Constants.UserId);
		if(t.size() !=0){
			return t;
		}else{
			log.debug("No TODO data");
			return null;
		}
		
	}
	public List<TODO> get7Tage() {
		log.info("Get TODO from the next seven days");
//		final Object[] param = new Object[] {todo.getDeadlineDatum(), 
//				todo.getDeadlineTime()};
		
		List<TODO> t= query_get7Tage.execute(Constants.UserId);

		log.debug("TODO List contains " + t.size() + " todo");
		return t;
	}
	

}
